import {defineStore} from 'pinia'
import {reactive} from "vue";
import {getCompany} from "@/api/api.company";

export const CompanyStore = defineStore("company", () => {
    const company = reactive({
        avatar: '',
        name: '',
        id: ''
    });
    const setCompany = (data: any) => {
        if (data) {
            Object.assign(company, data);
            company.avatar = company.name.charAt(0);
        }
    }

    const doLoadCompany = async (id: any) => {
        await getCompany({id}).then(res => {
            setCompany(res.data || {});
        })
    }

    return {
        company,
        doLoadCompany
    }
})
